using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace Patchy
{
    class MyGroup
    {
        private MyDirectory mDir;
        private ArrayList mFiles = new ArrayList();
        // C# badly needs sets :(
        private Hashtable mSet = new Hashtable(StringComparer.OrdinalIgnoreCase);
        private string mAliasCombined;
        private int mMaxNameLength;

        public MyGroup(string dir)
        {
            mDir = new MyDirectory(dir);
        }

        public void AddFile(string orig, string fname)
        {
            if(!mSet.Contains(fname))
            {
                mSet.Add(fname, fname);
                mFiles.Add(new MyFile(orig, fname));
            }
        }

        public void Process()
        {
            foreach (MyFile file in mFiles)
            {
                mMaxNameLength = Math.Max(mMaxNameLength, file.ShortenedName.Length);
            }
            foreach (MyFile file in mFiles)
            {
                file.LongestNameLength = mMaxNameLength;
            }
            mFiles.Sort(StringComparer.OrdinalIgnoreCase);
        }

        public ArrayList Files
        {
            get { return mFiles; }
        }

        public string DirectoryName
        {
            get { return mDir.NormalisedName; }
        }

        // e.g. DIRECTORY2
        public string Alias
        {
            get { return mAliasCombined.Substring(1, mAliasCombined.IndexOf('%', 1) - 1); }
        }

        // e.g. mobile\\final\\
        public string NonAliasedPart
        {
            get { return mAliasCombined.Substring(mAliasCombined.IndexOf('%', 1) + 1); }
        }

        // e.g. %DIRECTORY2%mobile\\final\\
        public string AliasCombined
        {
            get { return mAliasCombined; }
            set { mAliasCombined = value; }
        }
    }
}
